from sqlalchemy import create_engine,Column,String,Integer,DateTime
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

# 创建引擎
engine = create_engine(
    # mysql+pymysql://用户名:密码@服务器/数据库?选项
    'mysql+pymysql://root:xuehaoning@127.0.0.1/game?charset=utf8',
    encoding='utf8'
)

# 创建会话类，用于连接到数据库，通过会话连接操作数据库
Session = sessionmaker(bind=engine)

# 创建实体类(数据库中表对应的类)的基类
Base = declarative_base()

# 创建实体类
# class myGame(Base):
#     __tablename__ = 'fcmgame' # 声明该类与哪个表关联
#     bizId = Column(String(20),primary_key=True)  # 游戏备案识别码
#     abbreviation = Column(String(10)) # 游戏名简称
#     gamename = Column(String(50)) # 中文游戏全名

class Game_userinfo(Base):
    __tablename__ = 'userinfo'
    id = Column(Integer, primary_key=True,autoincrement=True)
    username = Column(String(50)) # 用户名
    user_email = Column(String(50),unique=True,nullable=False,default=False)
    time = Column(DateTime)

class number(Base):
    __tablename__ = 'count'
    id = Column(Integer, primary_key=True,autoincrement=True)
    count = Column(Integer)

class Game_userinfo_record(Base):
    __tablename__ = 'userinfos'
    id = Column(Integer, primary_key=True,autoincrement=True)
    username = Column(String(50)) # 用户名
    user_email = Column(String(50),unique=True,nullable=False,default=False)
    user_phone = Column(String(50),unique=True,nullable=False,default=False)
    time = Column(DateTime)

class register_info(Base):
    __tablename__ = 'register'
    id = Column(Integer, primary_key=True,autoincrement=True)
    user_email = Column(String(50),unique=True,nullable=False,default=False)
    user_phone = Column(String(50))
    time = Column(DateTime)


if __name__ == '__main__':
    Base.metadata.create_all(engine)
